/*
 * @Author: yhy
 * @Date: 2022-03-16 09:40:27
 * @LastEditTime: 2022-04-12 10:10:14
 * @LastEditors: yhy
 * @Description:
 */
// 统一封装方法
// 每个方法负责一个url地址
// 逻辑页面, 导入这个接口方法, 就能发请求
import axios from '@/utils/request'
// import { getToken } from '@/utils/token'

// 登陆 接口
export const loginApi = ({ mobile, code }) => {
  return axios({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

// 获取所有频道
export const getAllChannelsApis = () => {
  return axios({
    url: '/v1_0/channels',
    method: 'GET'
  })
}

// 获取 用户选择的频道
// 注意: 如果用户没有登陆 则返回默认频道列表
export const getUserChannelsApi = () => {
  return axios({
    url: '/v1_0/user/channels'
    // headers: {
    //   Authorization: `Bearer ${getToken()}`
    // }
  })
}

// 更新用户已选频道
export const updateChannelsApi = ({ channels }) => {
  return axios({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels // 用户已选整个频道数组
    }
  })
}

// 删除用户频道
export const removeChannelsApi = (target) => {
  return axios({
    url: `/v1_0/user/channels/${target}`,
    method: 'DELETE'
  })
}

// 获取新闻 文章列表
export const getAllArticleListApi = ({ channel_id, timestamp }) => {
  return axios({
    url: '/v1_0/articles',
    // headers: {
    //   Authorization: `Bearer ${getToken()}`
    // },
    params: {
      channel_id,
      timestamp
    }
  })
}

// 反馈接口- 不感兴趣
export const articleDislikeAPI = ({ target }) => {
  return axios({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    // headers: {
    //   Authorization: `Bearer ${getToken()}`
    // },
    data: {
      target
    }
  })
}

// 举报接口 - 反馈垃圾内容
export const articleReportsAPI = ({ target, type }) => {
  return axios({
    url: '/v1_0/article/reports',
    method: 'POST',
    // headers: {
    //   Authorization: `Bearer ${getToken()}`
    // },
    data: {
      target,
      type,
      remark: '如果想要使用 请在对应文件中添加判断条件'
    }
  })
}

// 搜索--获取联想建议
export const suggestListApi = ({ keywords }) => {
  return axios({
    url: '/v1_0/suggestion',
    params: {
      q: keywords
    }
  })
}
